﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Devtm.ServiceModel.Configurations;
using System.ServiceModel;

namespace Devtm.ServiceModel.Discovery
{
    
    public static class Helper
    {



        public static System.ServiceModel.Discovery.DiscoveryVersion GetDiscoveryVersion(this UrlBaseElement config)
        {

            System.ServiceModel.Discovery.DiscoveryVersion v = null;

            switch (config.DiscoveryVersion)
            {
                case DiscoveryVersionEnum.WSDiscovery11:
                    v = System.ServiceModel.Discovery.DiscoveryVersion.WSDiscovery11;
                    break;
                case DiscoveryVersionEnum.WSDiscoveryApril2005:
                    v = System.ServiceModel.Discovery.DiscoveryVersion.WSDiscoveryApril2005;
                    break;
                case DiscoveryVersionEnum.WSDiscoveryCD1:
                    v = System.ServiceModel.Discovery.DiscoveryVersion.WSDiscoveryCD1;
                    break;
            }

            return v;

        }


        public static System.ServiceModel.Discovery.DiscoveryEndpoint GetEndpoint(this ProbeElement config)
        {

            System.ServiceModel.Discovery.ServiceDiscoveryMode mode = (System.ServiceModel.Discovery.ServiceDiscoveryMode)Enum.Parse(typeof(System.ServiceModel.Discovery.ServiceDiscoveryMode), config.Mode.ToString());
           
            System.ServiceModel.Discovery.DiscoveryEndpoint d = new System.ServiceModel.Discovery.DiscoveryEndpoint(config.GetDiscoveryVersion(), mode, config.Binding, new EndpointAddress(new Uri(config.Uri)));
            
            return d;

        }

        public static System.ServiceModel.Discovery.AnnouncementEndpoint GetEndpoint(this AnnouncementElement config)
        {
            System.ServiceModel.Discovery.AnnouncementEndpoint d = new System.ServiceModel.Discovery.AnnouncementEndpoint(config.GetDiscoveryVersion(), config.Binding, new EndpointAddress(new Uri(config.Uri)));
            return d;
        }

    }

}
